home *** CD-ROM | disk | FTP | other *** search
/ Micromanía 92 / CDMM92_1.ISO / SOF 2 SDK / sof2sdk-101.msi / _92D6AC311BB48EBA344BBABC89DA6AB0 / _BF7E8CEC073C49A89ED6C05FD9261497 < prev    next >
Encoding:
Text File  |  2002-03-11  |  6.5 KB  |  310 lines

  1. // Copyright (C) 2001-2002 Raven Software.
  2. //
  3. //    User interface building blocks and support functions.
  4.  
  5. #include "ui_local.h"
  6.  
  7. // these are here so the functions in q_shared.c can link
  8. #ifndef UI_HARD_LINKED
  9.  
  10. /*
  11. =================
  12. Com_Error
  13.  
  14. reports an error to the console and shuts down any active game
  15. =================
  16. */
  17. void QDECL Com_Error( int level, const char *error, ... ) 
  18. {
  19.     va_list        argptr;
  20.     char        text[1024];
  21.  
  22.     va_start (argptr, error);
  23.     vsprintf (text, error, argptr);
  24.     va_end (argptr);
  25.  
  26.     trap_Error( va("%s", text) );
  27. }
  28.  
  29. /*
  30. =================
  31. Com_Printf
  32.  
  33. Outputs text to the console
  34. =================
  35. */
  36. void QDECL Com_Printf( const char *msg, ... ) 
  37. {
  38.     va_list        argptr;
  39.     char        text[1024];
  40.  
  41.     va_start (argptr, msg);
  42.     vsprintf (text, msg, argptr);
  43.     va_end (argptr);
  44.  
  45.     trap_Print( va("%s", text) );
  46. }
  47.  
  48. #endif
  49.  
  50. char *UI_Argv( int arg ) {
  51.     static char    buffer[MAX_STRING_CHARS];
  52.  
  53.     trap_Argv( arg, buffer, sizeof( buffer ) );
  54.  
  55.     return buffer;
  56. }
  57.  
  58.  
  59. char *UI_Cvar_VariableString( const char *var_name ) {
  60.     static char    buffer[MAX_STRING_CHARS];
  61.  
  62.     trap_Cvar_VariableStringBuffer( var_name, buffer, sizeof( buffer ) );
  63.  
  64.     return buffer;
  65. }
  66.  
  67.  
  68.  
  69. static void    UI_Cache_f() 
  70. {
  71.     Display_CacheAll();
  72. }
  73.  
  74. /*
  75. =================
  76. UI_ConsoleCommand
  77. =================
  78. */
  79. qboolean UI_ConsoleCommand( int realTime ) 
  80. {
  81.     char    *cmd;
  82.  
  83.     uiInfo.uiDC.frameTime = realTime - uiInfo.uiDC.realTime;
  84.     uiInfo.uiDC.realTime = realTime;
  85.  
  86.     cmd = UI_Argv( 0 );
  87.  
  88.     // ensure minimum menu data is available
  89.     //Menu_Cache();
  90.     if ( Q_stricmp (cmd, "ui_report") == 0 ) 
  91.     {
  92.         UI_Report();
  93.         return qtrue;
  94.     }
  95.     
  96.     if ( Q_stricmp (cmd, "ui_reload") == 0 ) 
  97.     {
  98.         UI_Reload();
  99.         return qtrue;
  100.     }
  101.  
  102.     if ( Q_stricmp ( cmd, "ui_openmenu" ) == 0 )
  103.     {
  104. //        Menus_CloseAll ( );
  105.         Menus_OpenByName ( UI_Argv(1) );
  106.         return qtrue;
  107.     }
  108.  
  109.     if ( Q_stricmp (cmd, "remapShader") == 0 ) 
  110.     {
  111.         if (trap_Argc() == 4) 
  112.         {
  113.             char shader1[MAX_QPATH];
  114.             char shader2[MAX_QPATH];
  115.             Q_strncpyz(shader1, UI_Argv(1), sizeof(shader1));
  116.             Q_strncpyz(shader2, UI_Argv(2), sizeof(shader2));
  117.             trap_R_RemapShader(shader1, shader2, UI_Argv(3));
  118.             return qtrue;
  119.         }
  120.     }
  121.  
  122.     if ( Q_stricmp (cmd, "ui_cache") == 0 ) 
  123.     {
  124.         UI_Cache_f();
  125.         return qtrue;
  126.     }
  127.  
  128.     if ( Q_stricmp (cmd, "ui_cdkey") == 0 ) 
  129.     {
  130.         //UI_CDKeyMenu_f();
  131.         return qtrue;
  132.     }
  133.  
  134.     return qfalse;
  135. }
  136.  
  137. /*
  138. =================
  139. UI_Shutdown
  140. =================
  141. */
  142. void UI_Shutdown( void ) 
  143. {
  144. }
  145.  
  146. /*
  147. ================
  148. UI_AdjustFrom640
  149.  
  150. Adjusted for resolution and screen aspect ratio
  151. ================
  152. */
  153. void UI_AdjustFrom640( float *x, float *y, float *w, float *h ) {
  154.     // expect valid pointers
  155. #if 0
  156.     *x = *x * uiInfo.uiDC.scale + uiInfo.uiDC.bias;
  157.     *y *= uiInfo.uiDC.scale;
  158.     *w *= uiInfo.uiDC.scale;
  159.     *h *= uiInfo.uiDC.scale;
  160. #endif
  161.  
  162.     *x *= uiInfo.uiDC.xscale;
  163.     *y *= uiInfo.uiDC.yscale;
  164.     *w *= uiInfo.uiDC.xscale;
  165.     *h *= uiInfo.uiDC.yscale;
  166.  
  167. }
  168.  
  169. void UI_DrawNamedPic( float x, float y, float width, float height, const char *picname ) {
  170.     qhandle_t    hShader;
  171.  
  172.     hShader = trap_R_RegisterShaderNoMip( picname );
  173.     UI_AdjustFrom640( &x, &y, &width, &height );
  174.     trap_R_DrawStretchPic( x, y, width, height, 0, 0, 1, 1, NULL, hShader );
  175. }
  176.  
  177. void UI_DrawHandlePic( float x, float y, float w, float h, qhandle_t hShader ) {
  178.     float    s0;
  179.     float    s1;
  180.     float    t0;
  181.     float    t1;
  182.  
  183.     if( w < 0 ) {    // flip about vertical
  184.         w  = -w;
  185.         s0 = 1;
  186.         s1 = 0;
  187.     }
  188.     else {
  189.         s0 = 0;
  190.         s1 = 1;
  191.     }
  192.  
  193.     if( h < 0 ) {    // flip about horizontal
  194.         h  = -h;
  195.         t0 = 1;
  196.         t1 = 0;
  197.     }
  198.     else {
  199.         t0 = 0;
  200.         t1 = 1;
  201.     }
  202.     
  203.     UI_AdjustFrom640( &x, &y, &w, &h );
  204.     trap_R_DrawStretchPic( x, y, w, h, s0, t0, s1, t1, NULL, hShader );
  205. }
  206.  
  207. /*
  208. ================
  209. UI_FillRect
  210.  
  211. Coordinates are 640*480 virtual values
  212. =================
  213. */
  214. void UI_FillRect( float x, float y, float width, float height, const float *color ) 
  215. {
  216.     trap_R_SetColor( color );
  217.  
  218.     UI_AdjustFrom640( &x, &y, &width, &height );
  219.     trap_R_DrawStretchPic( x, y, width, height, 0, 0, 0, 0, NULL, uiInfo.uiDC.whiteShader );
  220.  
  221.     trap_R_SetColor( NULL );
  222. }
  223.  
  224. void UI_DrawSides(float x, float y, float w, float h) {
  225.     UI_AdjustFrom640( &x, &y, &w, &h );
  226.     trap_R_DrawStretchPic( x, y, 1, h, 0, 0, 0, 0, NULL, uiInfo.uiDC.whiteShader );
  227.     trap_R_DrawStretchPic( x + w - 1, y, 1, h, 0, 0, 0, 0, NULL, uiInfo.uiDC.whiteShader );
  228. }
  229.  
  230. void UI_DrawTopBottom(float x, float y, float w, float h) {
  231.     UI_AdjustFrom640( &x, &y, &w, &h );
  232.     trap_R_DrawStretchPic( x, y, w, 1, 0, 0, 0, 0, NULL, uiInfo.uiDC.whiteShader );
  233.     trap_R_DrawStretchPic( x, y + h - 1, w, 1, 0, 0, 0, 0, NULL, uiInfo.uiDC.whiteShader );
  234. }
  235. /*
  236. ================
  237. UI_DrawRect
  238.  
  239. Coordinates are 640*480 virtual values
  240. =================
  241. */
  242. void UI_DrawRect( float x, float y, float width, float height, const float *color ) 
  243. {
  244.     trap_R_SetColor( color );
  245.  
  246.     UI_DrawTopBottom(x, y, width, height);
  247.     UI_DrawSides(x, y, width, height);
  248.  
  249.     trap_R_SetColor( NULL );
  250. }
  251.  
  252. void UI_SetColor( const float *rgba ) 
  253. {
  254.     trap_R_SetColor( rgba );
  255. }
  256.  
  257. void UI_UpdateScreen( qboolean IsLoading ) {
  258.     trap_UpdateScreen(IsLoading);
  259. }
  260.  
  261.  
  262. void UI_DrawTextBox (int x, int y, int width, int lines)
  263. {
  264.     UI_FillRect( x + BIGCHAR_WIDTH/2, y + BIGCHAR_HEIGHT/2, ( width + 1 ) * BIGCHAR_WIDTH, ( lines + 1 ) * BIGCHAR_HEIGHT, colorBlack );
  265.     UI_DrawRect( x + BIGCHAR_WIDTH/2, y + BIGCHAR_HEIGHT/2, ( width + 1 ) * BIGCHAR_WIDTH, ( lines + 1 ) * BIGCHAR_HEIGHT, colorWhite );
  266. }
  267.  
  268. qboolean UI_CursorInRect (int x, int y, int width, int height)
  269. {
  270.     if (uiInfo.uiDC.cursorx < x ||
  271.         uiInfo.uiDC.cursory < y ||
  272.         uiInfo.uiDC.cursorx > x+width ||
  273.         uiInfo.uiDC.cursory > y+height)
  274.         return qfalse;
  275.  
  276.     return qtrue;
  277. }
  278.  
  279. /*
  280. =====================
  281. UI_DrawText
  282.  
  283. Renders text on the screen
  284. =====================
  285. */
  286. void UI_DrawText ( float x, float y, qhandle_t font, float scale, vec4_t color, const char* text, int limit, int flags )
  287. {
  288.     x      *= uiInfo.uiDC.xscale;
  289.     y      *= uiInfo.uiDC.yscale;
  290.     scale *= uiInfo.uiDC.xscale;
  291.  
  292.     trap_R_DrawText ( (int)x, (int)y, font, scale, color, text, limit, flags );
  293. }
  294.  
  295. /*
  296. =====================
  297. UI_DrawTextWithCursor
  298.  
  299. Renders text on the screen with a blinking cursor
  300. =====================
  301. */
  302. void UI_DrawTextWithCursor ( float x, float y, qhandle_t font, float scale, vec4_t color, const char* text, int limit, int flags, int cursorPos, char cursor )
  303. {
  304.     x      *= uiInfo.uiDC.xscale;
  305.     y      *= uiInfo.uiDC.yscale;
  306.     scale *= uiInfo.uiDC.xscale;
  307.  
  308.     trap_R_DrawTextWithCursor ( (int)x, (int)y, font, scale, color, text, limit, flags, cursorPos, cursor );
  309. }
  310.